//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System.Windows.Forms;
using GuidanceExplorer.Model;

namespace GuidanceExplorer.Controls
{
    /// <summary>
    /// Represents the root Views node in the tree.
    /// </summary>
    [MenuItemAttribute(510, "context\\New Folder", GuidanceExplorer.Commands.NewFolder, typeof(ModelItemMenuItemIsEditableCondition), Keys.None)]
    [MenuItemAttribute(520, "context\\New View", GuidanceExplorer.Commands.NewView, typeof(ModelItemMenuItemIsEditableCondition), Keys.None)]
    [MenuItemAttribute(530, "context\\New Search View", GuidanceExplorer.Commands.NewSearchView, typeof(ModelItemMenuItemIsEditableCondition), Keys.None)]
    [MenuItemAttribute(540, "context\\-", null, typeof(ModelItemMenuItemIsEditableCondition), Keys.None)]
    [MenuItemAttribute(560, "context\\Export as Library...", GuidanceExplorer.Commands.ExportGlobalViewsAsLibrary, Keys.None)]
    [MenuItemAttribute(561, "context\\Save View as...", GuidanceExplorer.Commands.SaveGlobalViewsAs, Keys.None)]
    public class GlobalViewsNode : ModelNode<GlobalViews>
    {
        /// <summary>
        /// Factory.
        /// </summary>
        /// <returns></returns>
        public static GlobalViewsNode New()
        {
            return new GlobalViewsNode();
        }

        /// <summary>
        /// Default private constructor.
        /// </summary>
        private GlobalViewsNode() : base("Library Views", 2, 2) { }

        /// <summary>
        /// Whether the node is editable.
        /// </summary>
        public override bool CanDrop(IModelItem modelNode)
        {
            if (modelNode == null)
            {
                return false;
            }

            ViewNode viewNode = modelNode as ViewNode;
            FolderNode folderNode = modelNode as FolderNode;
            SearchViewNode searchNode = modelNode as SearchViewNode;
            if (folderNode != null)
            {
                return true;
            }
            else if (viewNode != null)
            {
                /*
                 * Test for folders:
                 *  The root folders can't be droped in the library.
                 */

                //Root views cant be dragged
                if (viewNode.ModelInstance.RootView)
                {
                    return false;
                }

                return true;
            }
            else if (searchNode != null)
            {
                //Root views cant be dragged
                if (searchNode.ModelInstance.RootView)
                {
                    return false;
                }

                return true;
            }
            else
            {
                //Can't drop this model node.
            }
            return false;
        }

        public override bool IsEditable
        {
            get { return false; }
        }
    }
}

